package com.wy.servlet;

import com.wy.bean.User;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
@WebServlet("/login.do")
public class Login extends BaseServlet {

    protected void login(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String remoteHost = req.getRemoteHost();
        String format = new SimpleDateFormat("yyyy-MM-dd HH:ss:SSS").format(new Date());
        User user = new User(username, format, remoteHost);
        req.getSession().setAttribute("user", user);
    }

    protected void logout(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getSession().removeAttribute("user");

    }
}
